package com.cyandpos.pad.pay.presenter;



import com.cyandpos.pad.common.commondata.Constant;
import com.cyandpos.pad.netdata.R_Addpay;
import com.cyandpos.pad.pay.model.IPayNetRequestModel;
import com.cyandpos.pad.pay.model.IPayNetRequestModelImpl;
import com.cyandpos.pad.pay.view.IPayNetRequestView;
import com.cyandpos.pad.posdata.Member;
import com.cyandpos.pad.posdata.Payment;
import com.cyandpos.pad.posdata.QueryMemberRequest;
import com.cyandpos.pad.posdata.RefundOrder;
import com.cyandpos.pad.posdata.TicketInfo;

import java.util.List;

/**
 *  PayActivity网络请求——Presenter
 */

public class PayNetRequestPresenter  {

    private IPayNetRequestModel netModel;
    private IPayNetRequestView netView;
    private int count = 0;

    public PayNetRequestPresenter(IPayNetRequestView netView){
        this.netView = netView;
        this.netModel = new IPayNetRequestModelImpl();
    }

    //同步付款
    public void saveAddpayRequest(String orderNo, final List<Payment> payItems, int saleType, boolean clearFlag){
        if(clearFlag){
            netView.showProgress("正在取消付款，请稍等……");
        }else {
            netView.showProgress("正在付款，请稍等……");
        }
        netModel.loadAddpayInfo(orderNo, payItems,saleType,clearFlag, new IPayNetRequestModel.AddpayRequestListener() {
            @Override
            public void getAddpayInfoSuccess(R_Addpay addPayRes) {
                netView.dismissProgress();
                netView.saveAddpayRequestData(addPayRes);
            }

            @Override
            public void getAddpayInfoFailure(String msg) {
                netView.dismissProgress();
                netView.saveAddpayRequestFail(msg,payItems);
            }
        });
    }

    /**
     * 订单完成接口
     * @param mTicket 小票
     * @param isCancelAfterSwipe 返券后刷卡取消标志    true 取消
     */
    public void saveCommitPayRequest(TicketInfo mTicket,boolean isCancelAfterSwipe){
        netView.showProgress("正在保存订单信息，请稍等……");
        netModel.loadCommitPayInfo(mTicket,isCancelAfterSwipe, new IPayNetRequestModel.CommitPayRequestListener() {
            @Override
            public void getCommitPayInfoSuccess(TicketInfo ticket, boolean isCancelAfterSwipe) {
                netView.dismissProgress();
                netView.saveCommitPayRequestData(ticket,isCancelAfterSwipe);
            }

            @Override
            public void getCommitPayInfoFailure(String msg) {
                netView.dismissProgress();
                netView.showLoadFailureMsg(msg, Constant.PAY_COMMITPAY_FAILID);
            }
        });
    }

    /**
     * 返券后刷卡查询会员信息
     * @param requestParam
     */
    public void getVipCardToGrantVoucher(QueryMemberRequest requestParam){
        netView.showProgress("正在查询会员信息信息，请稍等……");
        netModel.loadGetVipCardToGrantVoucher(requestParam, new IPayNetRequestModel.LoadGetVipCardToGrantVoucherListener() {

            @Override
            public void getloadGetVipCardToGrantVoucherSuccess(Member member) {
                netView.dismissProgress();
                netView.saveGetVipCardToGrantVoucher(member);
            }

            @Override
            public void getloadGetVipCardToGrantVoucherFailure(String msg) {
                netView.dismissProgress();
                netView.showLoadFailureMsg(msg, Constant.CZK_VIPCARD_FailID);
            }
        });
    }
    /**
     * 根据订金单号查询订金单详情
     * @param depositNo
     */
    public void queryDepositInfo(String depositNo){
        netView.showProgress("正在查询订金单信息，请稍等……");
        netModel.queryDepositInfo(depositNo, new IPayNetRequestModel.QueryDepositInfoListener() {

            @Override
            public void getDepositInfoSuccess(RefundOrder depositInfo) {
                netView.dismissProgress();
                netView.queryDepositInfoDataSuccess(depositInfo);
            }

            @Override
            public void getDepositInfoFailure(String msg) {
                netView.dismissProgress();
                netView.showLoadFailureMsg(msg, Constant.PAY_DEPOSIT_QUERY_FailID);
            }
        });
    }
}
